package vo

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type Result struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

const (
	ERROR   = -1
	SUCCESS = 0
)

func SuccessE(c *gin.Context) {
	c.JSON(http.StatusOK, Result{
		Code: SUCCESS,
		Msg:  "success",
	})
}

func Success(data interface{}, c *gin.Context) {
	c.JSON(http.StatusOK, Result{
		Code: SUCCESS,
		Msg:  "success",
		Data: data,
	})
}

func Fail(msg string, c *gin.Context) {
	c.JSON(http.StatusOK, Result{
		Code: ERROR,
		Msg:  msg,
		Data: nil,
	})
}

func FailH(httpCode int, msg string, c *gin.Context) {
	c.JSON(httpCode, Result{
		Code: ERROR,
		Msg:  msg,
		Data: nil,
	})
}

func FailB(bizCode int, msg string, c *gin.Context) {
	c.JSON(http.StatusOK, Result{
		Code: bizCode,
		Msg:  msg,
		Data: nil,
	})
}

func FailHB(httpCode int, bizCode int, msg string, c *gin.Context) {
	c.JSON(httpCode, Result{
		Code: bizCode,
		Msg:  msg,
		Data: nil,
	})
}
